/**
 * Created by Mark_ren on 2016/11/28.
 * 苟富贵,無相忘
 */
var express = require('express');
var moment = require("moment");
var router = express.Router();
var co = require('co');
var seqModule = require('./createModules');
var seq = new seqModule();
var fs = require('fs');
//查询省份
router.get('/getprovince', function(req, res, next) {
    co(function () {

        seq.sequelize.query(" select id,province from tp_ccdt.member_hospital " +
            "group by province order by province ").spread(function(results){
            res.json({"success":true,"rows":results});
        });
    }).catch(function(e) {
        res.json({'success':false,'msg':'查询失败'});
        console.log(e);
    })
});


//查询城市 by province
router.get('/getcityByprovince', function(req, res, next) {
    co(function () {
        var province="";
        if(req.query.province!=undefined && req.query.province!=""){
            province=" and province ='"+req.query.province+"'";
        }
        seq.sequelize.query(" select id,province,city,name from member_hospital " +
            "where 1=1 "+province+" group by city order by city ").spread(function(results){
            res.json({"success":true,"rows":results});
        });
    }).catch(function(e) {
        res.json({'success':false,'msg':'查询失败'});
        console.log(e);
    })
});

//查询医院 by city
router.get('/gethospitalBycity', function(req, res, next) {
    co(function () {
        var city="";
        if(req.query.city!=undefined && req.query.city!=""){
            city=" and city ='"+req.query.city+"'";
        }
        seq.sequelize.query(" select id,province,city,name from member_hospital " +
            "where 1=1 "+city+" group by name order by name ").spread(function(results){
            res.json({"success":true,"rows":results});
        });
    }).catch(function(e) {
        res.json({'success':false,'msg':'查询失败'});
        console.log(e);
    })
});
module.exports = router;